<?php

class AdminIndexController extends ApplicationViewableController 
{
    public function onConstruct()
    {
        @session_start();
        
        if (!isset($_SERVER['PHP_AUTH_USER']) && (!Env::session('login') || Env::session('login') != 'gluck')) {
            header('WWW-Authenticate: Basic realm="My Realm"');
            header('HTTP/1.0 401 Unauthorized');
            exit;
        } else {
            if (Env::server('PHP_AUTH_USER') != 'gluck' || Env::server('PHP_AUTH_PW') != '$u4iInoTpax') {
                unset($_SERVER['PHP_AUTH_PW']);
                unset($_SERVER['PHP_AUTH_USER']);
                session_destroy();
                
                header("HTTP/1.0 403 Forbidden", null, 403);
                echo 'Error 403. Forbidden';
                die();
            }
            
            $_SESSION['user'] = Env::server('PHP_AUTH_USER');
        }
        
        // Global Controllers
        $this->attach(new AdminLayoutHeaderController(), 'LayoutHeader');
        $this->attach(new AdminLayoutFooterController(), 'LayoutFooter');
    }
}

?>